package com.softtown.modules.sys.controller;

import com.softtown.common.annotation.LogOperation;
import com.softtown.common.utils.Result;
import com.softtown.modules.sys.dto.TransferAuthorityDTO;
import com.softtown.modules.sys.service.CompSysUserApplService;
import com.softtown.modules.sys.service.SysCompService;
import com.softtown.modules.sys.vo.UserEmplPermitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Dingyayong
 * @Date: 2019/6/3 17:59
 * @Description: 公司成员管理
 */

@RestController
@RequestMapping("/sys/manager")
@Api(tags = "公司成员管理")
public class ComUserMangerController {

    @Resource
    private SysCompService sysCompService;

    @Resource
    private CompSysUserApplService compSysUserApplService;

    @PostMapping("transfer")
    @ApiOperation("权限转让")
    @LogOperation("权限转让")
    public Result transfer(@RequestBody TransferAuthorityDTO transferAuthorityDTO) {
        sysCompService.transfer(transferAuthorityDTO.getCompId(),transferAuthorityDTO.getUserId());
        return new Result<>();
    }

    @PostMapping("permitList")
    @ApiOperation("成员加入一览")
    @LogOperation("成员加入一览")
    public Result<UserEmplPermitVO> permitList(@RequestBody Long compId) {
        UserEmplPermitVO userEmplPermitVO = compSysUserApplService.permitList(compId);
        return new Result<UserEmplPermitVO>().ok(userEmplPermitVO);
    }

    @PostMapping("refuse")
    @ApiOperation("成员加入拒绝")
    @LogOperation("成员加入拒绝")
    public Result refuse(@RequestBody String empl) {
        String userId = JSONObject.fromObject(empl).get("userId").toString();
        String compId = JSONObject.fromObject(empl).get("compId").toString();
        String compUserId = JSONObject.fromObject(empl).get("compUserId").toString();
        compSysUserApplService.refuse(Long.valueOf(compId), Long.valueOf(userId), Long.valueOf(compUserId));
        return new Result<>();
    }
}
